package threadPr;

public class ShutDownHookDemo {
	public ShutDownHookDemo() {
		Thread t = new MyShutDownHookThread("This will execute at end");
		Runtime.getRuntime().addShutdownHook(t);
		System.out.println("Doing some ");
		int i = 0;
		while (true) {
			System.out.print(".");
			try {
				i++;
				Thread.sleep(300);
				if (i > 5) {
					System.exit(0);
				}
			} catch (InterruptedException ie) {
			}
		}
	}

	public static void main(String args[]) {
		new ShutDownHookDemo();
	}

}

class MyShutDownHookThread extends Thread {
	protected String message;
	public MyShutDownHookThread(String message) {
		this.message = message;
	}
	public void run() {
		System.out.println(message);
	}
}